package com.cfc.stage1;

import org.junit.Test;

/**
 * @description:
 *  https://leetcode.cn/problems/remove-element/
 * @author: yangxuan10
 * @create: 2024-04-10 13:38
 **/
public class RemoveElement {


    @Test
    public void test(){
        int [] a = new int[]{1,3,5,6};
        System.out.println(searchInsert(a,5));
    }

    public int searchInsert(int[] nums, int target) {
        return searchInsert(nums,target,0,nums.length-1);
    }

    public int searchInsert(int[] nums, int target,int start,int end) {
        if (start >= end) {
            return nums[start] < target ? start+1 : start;
        }
        int midindex = (start+end) / 2;
        while(true){
            if (nums[midindex] == target) {
                return midindex;
            } else if (nums[midindex] > target){
                return searchInsert(nums,target,start,midindex-1);
            } else {
                return searchInsert(nums,target,midindex+1,end);
            }
        }
    }

}